package com.zqxq.lottery.controller.sys;

import com.baomidou.mybatisplus.plugins.Page;
import com.zqxq.common.constant.Result;
import com.zqxq.common.enums.CodeEnum;
import com.zqxq.common.utils.StrUtils;
import com.zqxq.lottery.entity.o2o.sys.LotteryKindO2O;
import com.zqxq.lottery.entity.po.sys.LotteryKindPO;
import com.zqxq.lottery.mapper.order.UserOrderMapper;
import com.zqxq.lottery.service.sys.ILotteryKindService;
import com.zqxq.lottery.entity.bo.sys.LotteryKindBO;
import com.zqxq.lottery.entity.vo.sys.LotteryKindVO;
import com.zqxq.lottery.util.CurrencyUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;


/**
 * 说    明：   竞猜种类
 * 创 建 人：	一刀·胡
 * 创建时间：	2018/3/16 9:49
 * 修 改 人：
 * 修改日期：
 **/
@RestController
@Slf4j
public class LotteryKindController extends SysBaseController{

    @Autowired
    private ILotteryKindService lotteryKindService;
    @Autowired
    private UserOrderMapper userOrderMapper;

    @ApiOperation(value="条件查询彩种", notes="分页条件查询彩种")
    @PostMapping("/lotterykind/list")
    public Result list(@RequestBody LotteryKindBO search){
        Result rs = new Result();
        try{
            List<LotteryKindVO> list = lotteryKindService.queryList(search);
            rs.setData(list);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("List LotteryKind Error:",e);
        }
        return rs;
    }

    @ApiOperation(value="分页条件查询彩种", notes="分页条件查询彩种")
    @PostMapping("/lotterykind/page")
    public Result page(@RequestBody LotteryKindBO search){
        Result rs = new Result();
        try{
            Page page = lotteryKindService.queryPage(search);
            rs.setData(page);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("List LotteryKind Error:",e);
        }
        return rs;
    }

    @PostMapping("/lotterykind/get")
    public Result get(@RequestParam Long id){
        Result rs = new Result();
        try{
            LotteryKindPO po = lotteryKindService.selectById(id);
            LotteryKindVO vo = new LotteryKindVO();
            if(null != po)
                vo = LotteryKindO2O.toVO(po);
            rs.setData(vo);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("Get LotteryKind Error:",e);
        }
        return rs;
    }

    //添加、修改
    @PostMapping("/lotterykind/add")
    public Result add(@RequestBody LotteryKindVO vo){
        Result rs = new Result();
        try{
            vo = lotteryKindService.save(vo);
            rs.setData(vo);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("Add LotteryKind Error:",e);
        }
        return rs;
    }

    //0-隐藏； 1-显示
    @PostMapping("/lotterykind/updateStatus")
    public Result updateStatus(@RequestParam Long id, @RequestParam int status){
        Result rs = new Result();
        try{
            lotteryKindService.updateStatus(id,status);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("UpdateStatus LotteryKind Error:",e);
        }
        return rs;
    }


    //排序
    @PostMapping("/lotterykind/updateSort")
    public Result updateSort(@RequestParam Long id, @RequestParam int sort){
        Result rs = new Result();
        try{
            sort = lotteryKindService.updateSort(id,sort);
            rs.setData(sort);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("UpdateSort LotteryKind Error:",e);
        }
        return rs;
    }

}
